package com.example.demo.mapper;

import com.example.demo.model.ArticleInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 马拉圈
 * Date: 2023-09-03
 * Time: 20:37
 */
@Mapper
public interface ArticleMapper {

    @Insert("insert into articleinfo (title, content, summary, uid, photo) values (#{title}, #{content}, #{summary}, #{uid}, #{photo})")
    int insert(ArticleInfo articleInfo);

    @Select("select * from articleinfo where uid = #{uid} order by id desc")
    List<ArticleInfo> getListByUid(@Param("uid") int uid); //越晚发布排在越前

    @Delete("delete from articleinfo where id = #{id} and uid = #{uid}")
    int delete(ArticleInfo articleInfo);

    @Select("select * from articleinfo where id = #{id} and uid = #{uid}")
    ArticleInfo getArticleCheck(ArticleInfo articleInfo);//检查权限的查询文章

    @Select("select * from articleinfo where id = #{id}")
    ArticleInfo getArticle(ArticleInfo articleInfo);

    @Update("update articleinfo set content = #{content}, title = #{title}, summary = #{summary}, updatetime = now() where id = #{id} and uid = #{uid}")
    int updateArticle(ArticleInfo articleInfo);

    @Select("select count(*) from articleinfo where uid=#{uid}")
    int getArtNumberByUid(@Param("uid") int uid);

    @Update("update articleinfo set rcount = rcount + 1 where id = #{aid}")
    int incrementRCount(@Param("aid") int aid);

    @Select("select * from articleinfo order by id desc limit #{limit} offset #{offset}")
    List<ArticleInfo> getSubList(@Param("limit") int limit, @Param("offset") int offset);

    @Select("select count(*) from articleinfo")
    int getNumber();
}
